//
//  NSAttributedString+Extension.swift
//  VVeibo21
//
//  Created by Apple on 16/11/5.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

extension NSAttributedString {
    //  根据表情模型创建表情富文本
    class func attributedStringWithEmoticon(emoticon: HMEmoticon, font: UIFont) -> NSAttributedString {
        let image = UIImage(named: emoticon.fullPath!)
        // 根据 UIImage 对象创建文本附件(NSTextAttachment)
        let attachment = HMTextAttachment()
        //  给文本附件设置显示的图片
        attachment.image = image
        //  设置表情模型
        attachment.emoticon = emoticon
        //  设置成为文字大小
        let fontHeight = font.lineHeight
        //  文本附件bounds大小
        //  设置 bounds 会相应子控件的显示位置
        attachment.bounds = CGRect(x: 0, y: -4, width: fontHeight, height: fontHeight)
        // 根据文本附件创建富文本(NSAttributedString)
        let attributedStr = NSAttributedString(attachment: attachment)
    
        return attributedStr
    }
    
    


}
